package solved;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.TreeMap;

/*
ID:		liluyan1
LANG:	JAVA
TASK:	rect1
*/
public class rect1 {
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new FileReader("rect1.in"));
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
				"rect1.out")));
		new rect1().solve(f, out);
		out.close();
		System.exit(0);
	}
	
	private void solve(BufferedReader f, PrintWriter out) throws IOException {
		int[] a = read(f, 3);
		int A = a[0];
		int B = a[1];
		int N = a[2];
		
		ArrayList<Rect> res = new ArrayList<Rect>();
		res.add(new Rect(0, 0, A, B, 1));
		
		for (int i=0; i<N; i++) {
			a = read(f, 5);
			Rect r = new Rect(a[0], a[1], a[2], a[3], a[4]);
			add(res, r);
		}
		print(res, N, out);
	}
	
	private void print(ArrayList<Rect> res, int N, PrintWriter out) {
		TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
		for (Rect r : res) {
			int area = (r.x1 - r.x0) * (r.y1 - r.y0);
			if (!map.containsKey(r.color)) {
				map.put(r.color, area);
			}
			else {
				map.put(r.color, map.get(r.color) + area);
			}
		}
		
		for (int i : map.keySet()) {
			out.println(i + " " + map.get(i));
		}
	}
	
	private void add(ArrayList<Rect> res, Rect r) {
		ArrayList<Rect> temp = new ArrayList<Rect>();
		temp.addAll(res);
		res.clear();
		
		for (Rect s : temp) {
			if (r.x1 < s.x0 || r.x0 > s.x1 || r.y1 < s.y0 || r.y0 > s.y1) {
				res.add(s);
				continue;
			}
			
			addRect(res, s.x0, r.y1, r.x0, s.y1, s);
			addRect(res, 
					Math.max(r.x0, s.x0), 
					r.y1, 
					Math.min(r.x1, s.x1), 
					s.y1, 
					s);
			addRect(res, r.x1, r.y1, s.x1, s.y1, s);
			
			addRect(res, 
					s.x0, 
					Math.max(r.y0, s.y0), 
					r.x0, 
					Math.min(r.y1, s.y1), 
					s);
			addRect(res, 
					r.x1, 
					Math.max(r.y0, s.y0),  
					s.x1, 
					Math.min(r.y1, s.y1), 
					s);
			
			addRect(res, s.x0, s.y0, r.x0, r.y0, s);
			addRect(res, 
					Math.max(r.x0, s.x0), 
					s.y0, 
					Math.min(r.x1, s.x1), 
					r.y0, 
					s);
			addRect(res, r.x1, s.y0, s.x1, r.y0, s);
		}
		
		res.add(r);
		temp.clear();
	}
	
	private void addRect(ArrayList<Rect> res, int x0, int y0, int x1, int y1, Rect s) {
		if (s.contains(x0, y0) && s.contains(x1,  y1) && x1 > x0 && y1 > y0) {
			res.add(new Rect(x0, y0, x1, y1, s.color));
		}
	}
	
	private class Rect {
		int x0, y0, x1, y1;
		int color;
		public Rect(int x0, int y0, int x1, int y1, int color) {
			this.x0 = x0;
			this.y0 = y0;
			this.x1 = x1;
			this.y1 = y1;
			this.color = color;
		}
		
		public boolean contains(int x, int y) {
			return x>=x0 && x<=x1 && y>=y0 && y<=y1;
		}
	}
	
	public int read(BufferedReader f) throws IOException {
		return Integer.parseInt(f.readLine());
	}
	
	public int[] read(BufferedReader f, int N) throws IOException {
		String[] t = f.readLine().split(" ");
		int[] a = new int[N];
		for (int i=0; i<N; i++) {
			a[i] = Integer.parseInt(t[i]);
		}
		return a;
	}
}
